<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			/*与桥接模式有点相似*/

			// 对多个类组合调用，每一个模块都可以得到灵活的运用与高质量的复用。
			// 这种方式对于整体对象类的拆分无形中增加了结构的复杂性
			// 因此如果对象粒度很小，或者模块间的复用率很低并且变动不大，最好还是创建整体对象
			
			// 创建一位人类
			var Human = function(param){
				// 技能
				this.skill = param && param.skill || '保密';
				// 兴趣爱好
				this.hobby = param && param.hobby || '保密';
			}
			Human.prototype = {
				getSkill : function(){
					return this.skill;
				},
				getHobby : function(){
					return this.hobby;
				}
			}
			// 实例化姓名类
			var Named = function(name){
				var that = this;
				(function(name, that){
					that.wholeName = name;
					if (name.indexOf(' ') > -1) {
						that.FirstName = name.slice(0, name.indexOf(' '));
						that.secondName = name.slice(name.indexOf(' '));
					}
				})(name, that);
			}
			// 实例化职位类
			var Work = function(work){
				var that = this;
				(function(work, that){
					switch (work){
						case 'code':
							that.work = '工程师';
							that.workDescript = '每天沉醉于编程';
							break;
						case 'UI':
						case 'UE':
							that.work = '设计师';
							that.workDescript = '设计更似一种艺术';
							break;
						case 'teach':
							that.work = '教师';
							that.workDescript = '分享也是一种快乐';
							break;	
						default:
							that.work = work;
							that.workDescript = '对不起，我们还不清楚您所选择职位的相关描述';
							break;
					}
				})(work, that);
			}
			// 更换期望的职位
			Work.prototype.changeWork = function(work){
				this.work = work;
			}
			// 添加对职位的描述
			Work.prototype.changeDescript = function(desc){
				this.workDescript = desc;
			}
			/*
			 * 应聘者建造者
			 * 参数 name : 姓名(姓与名空格隔开)
			 * 参数 work : 期望职位
			 */
			var Person = function(name, work){
				var _person = new Human();
				_person.name = new Named(name);
				_person.work = new Work(work);
				return _person;
			}
			var person = new Person('chen yongli', 'code');
			console.log(person.skill);
			console.log(person.name.secondName);
			console.log(person.work.workDescript);
			person.work.changeDescript('修改一下职位描述');
			console.log(person.work.workDescript);
			
		</script>
	</body>
</html>
